package com.lunm.im.protocol;

import com.google.gson.*;


import java.lang.reflect.Type;

/**
 * @version 1.0.0
 * @Author shawn
 * @Date 2024/12/30 14:38
 */
public class TestSerializer {


    static class ClassCodec implements JsonSerializer<Class<?>>, JsonDeserializer<Class<?>> {
        @Override
        public Class<?> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {

            try {
                String str = json.getAsString();
                return Class.forName(str);
            } catch (ClassNotFoundException e) {
                throw new JsonParseException(e);
            }
        }

        @Override
        public JsonElement serialize(Class<?> clazz, Type type, JsonSerializationContext context) {
            return new JsonPrimitive(clazz.getName());
        }
    }
}
